const config = require("../config/db");
const mysql2 = require("mysql2");

let pool = mysql2.createPool(config)

class errModel {
    constructor(name, code, message) {
        this.name = name;
        this.code = code;
        this.message = message;
    }

    static create = (name, code, message) => new errModel(name, code, message)
}


let handleErr = err => console.log(err)

/**
 *
 * @param errObject
 */


function addErrLogToMySQL(errObject) {
    let tableName = `error_log`;
    let statement = `insert into ${tableName}
                     set ?`
    pool.getConnection((err, connection) => {
        if (err) return handleErr(err)
        connection.query(statement, errObject, (err, rows) => {
            if (err) return handleErr(err)
        })
        connection.release()
    })
}

module.exports = {addErrLogToMySQL}
